home *** CD-ROM | disk | FTP | other *** search
/ Learn Microsoft Visual Basic 6.0 Now / Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO / media / chap02 / b02d015.cc2 < prev    next >
Text File  |  1998-06-07  |  5KB  |  105 lines

  1. 0, When you write programs that interact 
  2. 2, with the user you'll want to use input 
  3. 5, controls that present choices and receive 
  4. 7, user input. I created this online shopper 
  5. 10, program to demonstrate four input 
  6. 12, controls you may want to use: the option 
  7. 15, button control, the checkbox control, the 
  8. 18, listbox control, and the combobox control. 
  9. 22, An option button displays a list of 
  10. 24, choices, but requires that you choose only 
  11. 27, one. In this program every choice I make 
  12. 30, is displayed graphically on the right 
  13. 32, side so that you can see immediately 
  14. 34, what's going on. A collection of checkboxes 
  15. 39, allows you to choose one or more 
  16. 42, choices. And if you choose you can choose no 
  17. 46, choices. Checkboxes allow you a lot of 
  18. 49, flexibility in gathering input. A listbox 
  19. 53, allows you to choose one choice and only 
  20. 55, one choice from a list. And if you like, 
  21. 58, you can have a default choice. Finally, 
  22. 61, a combobox is a compact listbox that 
  23. 64, displays one or more choices and gives you 
  24. 67, an opportunity for a default. Now that 
  25. 71, you've had a chance to see the input 
  26. 72, controls in action let's examine the 
  27. 75, program code that makes them work. I'll stop 
  28. 80, the program and double-click the 
  29. 83, answering machine checkbox to look at the 
  30. 87, program code that processes all the 
  31. 91, checkboxes. The check1_click event procedure 
  32. 95, contains the program code that runs when the 
  33. 97, user clicks the answering machine 
  34. 99, checkbox in the program. The important keyword 
  35. 104, here is check1.value, which should be 
  36. 109, read as the value property of the first 
  37. 111, checkbox object. Check1 is the name of 
  38. 114, the first checkbox created on the form. 
  39. 117, And subsequent checkboxes were check2, 
  40. 119, check3, and so on. The value property is a 
  41. 124, property that changes when a user clicks 
  42. 126, the checkbox on the form. When an x or 
  43. 131, a checkmark appears in the checkbox the 
  44. 133, value of the property is set to 1. If 
  45. 136, the checkbox is blank the value property 
  46. 138, is set to 0. In this case, if the 
  47. 141, property evaluates to 1 the program loads a 
  48. 145, picture of an answering machine into the 
  49. 147, second image box on the form and makes the 
  50. 150, picture visible. Otherwise, if the 
  51. 155, value property is 0 then a picture is 
  52. 159, removed from that image box on the form. If 
  53. 163, this all seems a little bit odd don't 
  54. 164, worry, you'll learn more about if and 
  55. 166, decision structures in Chapter 5. Now I'll 
  56. 171, close the code window and double-click the 
  57. 174, peripherals listbox on the form. Here, 
  58. 177, you'll see code that executes when the 
  59. 179, user clicks an item in the peripheral 
  60. 181, listbox. In this case, the important keyword 
  61. 184, is list1.listIndex, which is read as 
  62. 188, the list index property in the first list 
  63. 191, object. After the user makes a selection 
  64. 194, in the listbox, the list index property 
  65. 197, returns a number that corresponds to 
  66. 199, the location of the item in the listbox. 
  67. 203, The first item is numbered 0. The second 
  68. 206, item is numbered 1 and so on. The actual 
  69. 209, text of the choice is also returned in 
  70. 211, the list1.text property. Visual Basic 
  71. 215, programmers often use this value in their 
  72. 218, programs, although I didn't choose to 
  73. 220, use it here. Now I'll close the code 
  74. 222, window and double-click the form itself to 
  75. 229, show the code that is associated with the 
  76. 231, form when it is first loaded and run. 
  77. 234, This is called the form load event 
  78. 235, procedure, and is executed the first time that 
  79. 239, the form loads, usually at the very 
  80. 241, beginning of the program. Programmers put 
  81. 243, special statements in this special 
  82. 245, procedure if they want them executed every time 
  83. 247, a program starts. As in the online 
  84. 250, shopper program, the statements often 
  85. 253, reflect or define an aspect of the user 
  86. 255, interface that couldn't be created using the 
  87. 258, toolbox controls and the properties 
  88. 259, window. The first line holds a statement that 
  89. 264, loads the personal computer window's 
  90. 266, metafile into the picture property of the 
  91. 269, image1 object. The next three lines add 
  92. 272, the items to the peripherals listbox, 
  93. 275, the list1 object in the program. The key 
  94. 278, method here is addItem, which will add an 
  95. 280, item to either the listbox, or below, 
  96. 284, items can be added to the combobox. So 
  97. 290, we've seen how option buttons, checkboxes, 
  98. 292, and listboxes, along with comboboxes, 
  99. 295, are created in a program. To learn more 
  100. 298, about the program code and the online 
  101. 300, shopper program itself load the demo 2-3 
  102. 304, program in your Learn Visual Basic Now 
  103. 305, sample file directory and play around with 
  104. 307, it a little bit.
  105. 309, END